package com.membership.stumembership.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.membership.stumembership.domain.Membership;
import com.membership.stumembership.service.MembershipService;
import com.membership.stumembership.utils.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/membership")
@RequiredArgsConstructor
public class MembershipController {
    //@Autowired
    //@Resource
    private final MembershipService membershipService;
    @RequestMapping("/getAll")
    public Object selectAll(){
        return membershipService.list((Wrapper<Membership>) null);
    }
    @RequestMapping("/selectMemByPage")
    public Object selectByMemPage(Membership mem, Page<Membership> page){
        return membershipService.selectByMemPage(page,mem);
    }
    @RequestMapping("/getAllVue")
    public Object getAllVue(Page<Membership> page){
        return new Result(0,"成功", (Object) membershipService.page(page),
                (int) membershipService.count());
    }
    @RequestMapping("/add")
    public Object add(@RequestBody Membership membership){
        Membership mspe=membershipService.getOne(new QueryWrapper<Membership>().eq("mspe", membership.getMspe()));
        if(mspe !=null){
            return new Result(0,"添加失败，该系已存在！");
        }
       return membershipService.save(membership);
    }
    @RequestMapping("/delete")
    public Object delete(@RequestBody Membership mem){
        return membershipService.removeById(mem.getMid());
    }
    @RequestMapping("/update")
    public Object update(@RequestBody Membership mem){
        return membershipService.updateById(mem);
    }
}
